import React from 'react';
import {
  Form,
  Input,
  Button,
  DatePicker,
  Select,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload,
  Row,
  Col
} from 'antd';
import InnerTable from 'components/DBTable/InnerTable.js';
import ajax from 'utils/ajax';
import loginVerify from 'utils/loginVerify';


const FormItem = Form.Item;
const ButtonGroup = Button.Group;

/**
 * 内部表格组件
 */
class BankcardSwitchInnerTable extends InnerTable {

  onChangeState = (status) => {
    let text = (status == 1 ? '启用' : '关闭');
    Modal.confirm({
      title:  '确认' + text + '?',
      content: `${this.state.selectedRows[0].cardBankName}${this.state.selectedRows[0].cardBankCode}`,
      // 这里注意要用箭头函数, 否则this不生效
      onOk: () => {
        ajax.post({
          url: '/bankcard/update',
          params: { status, id: this.state.selectedRows[0].id },
          success: (result) => {
            if(result.errorCode == 300) {
              notification.error({
                message: '操作失败，请重试!',
                duration: 3,
              });
            }else {
              notification.success({
                message: `${text}成功`,
                duration: 3,
              });
              this.props.refresh();
            }
          },
          error: (xhr) => {
            notification.error({
              message: '操作失败，请重试!',
              duration: 3,
            });
          }
        });
      },
    });
  }

  prepareToolBar = () =>{
    let isButtondisabled = false;

    if (this.state.selectedRowKeys.length > 0) {  // 是否选择
      isButtondisabled = true;
    }

    if (this.state.selectedRowKeys.length > 1) {  // 是否选择了多项
      isButtondisabled = false;
    }


    var items = [];
    let selectRows = this.state.selectedRows[0];
    if(!selectRows){ //如果没有选择
      items.push(<Button key='roleAssignBtn' disabled={true}>
        <Icon type="poweroff"/>是否开启
      </Button>)
    }else{
      // console.log(selectRows.status);
      if (selectRows.status == 1) {
        items.push(<Button key='roleAssignBtn' disabled={!isButtondisabled} onClick={e=>this.onChangeState(0)}>
          <Icon type="logout"/>关闭
        </Button>)
      } else if (selectRows.status == 0){
        items.push(<Button key='roleAssignBtn' disabled={!isButtondisabled} onClick={e=>this.onChangeState(1)}>
          <Icon type="poweroff"/>启用
        </Button>)
      }

    }

    return items;
  }

 

}

export default BankcardSwitchInnerTable;
